﻿using Common.Contract;
using Common.Contract.Customer.Identifier;
using Common.Contract.Customer.Record;
using Common.Contract.DataCenter.Record;
using Common.Contract.DataCenter.Request;
using Common.Contract.SaleOut.Record;
using Common.Service.Command;
using Common.Service.Queue;
using Common.Util;
using DataCenter.Configuration;
using DataCenter.Model.Interface;
using DataCenter.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataCenter.ServiceCommand
{
    public class UpdateMrpServiceCommand : ProviderQueueCommand<IProviderFactory, MrpRecord, ResponseRecord>
    {
        public UpdateMrpServiceCommand(IProviderFactory provider) : base(provider) { }
        protected override void Validate(MrpRecord record)
        {
            if (record == null) throw new ArgumentNullException("request");
        }

        protected override bool OnExecute(ResponseRecord response)
        {
            var mpr = Record;
            var obj = new MRP()
            {
                Model = mpr.Model,
                Mrp = mpr.Mrp,
                CreateDate = DateTime.Now,
                SoTransferDate = DateTime.Now,
                SoTransferFlag = BooleanString.TRUE,
            };

            var itemCheck = Providers.Mrp.Retrieve(Record.Model);
            if (itemCheck == null)
            {
                var resultitem1 = Providers.Mrp.Add(obj);
            }
            else
            {
                var resultitem2 = Providers.Mrp.Update(obj);
            }
            return true;
        }
    }
}
